import uuid
import random
import os
import django

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "TasteLink0.settings")
django.setup()
from datetime import datetime, timedelta
from app.models import (
    User, MerchantInfo, Category, Dish, Image,
    Order, OrderItem
)

# ================== Step 1: 创建商家 ==================
merchant = MerchantInfo.objects.create(
    shop_name="麦当劳",
    location="北京市朝阳区",
    contact_info="13800001111",
    introduction="全球知名快餐品牌"
)
print("✅ 商家已创建")

# ================== Step 2: 创建分类 ==================
category_1 = Category.objects.create(
    merchant=merchant,
    category_name="汉堡",
    sort_order=1
)
category_2 = Category.objects.create(
    merchant=merchant,
    category_name="饮料",
    sort_order=2
)
print("✅ 分类已创建")

# ================== Step 3: 创建菜品 ==================
dishes = []
for i in range(1, 11):  # 每个分类各5个菜品
    dishes.append(Dish(
        dish_id=uuid.uuid4(),
        merchant=merchant,
        category=category_1 if i <= 5 else category_2,
        dish_name=f"菜品{i}",
        price=round(random.uniform(10, 50), 2),
        stock=random.randint(0, 100),
        sort_order=i,
        status='on_shelf',
        customization_options={"spicy": "medium"} if i % 2 == 0 else None
    ))
Dish.objects.bulk_create(dishes)
print("✅ 菜品已创建")